﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using MillerApp.DataContract.Common.Entity;
using System.Reflection;

namespace MillerApp.Business.Rules.Common
{
    /// <summary>
    /// 规则运行器
    /// </summary>
    public class RuleEventRuner
    {
        public List<KeyValueEntry> RuleParams { get; set; }
        public RuleEntity Rule { get; set; }

        public void RuleExecute()
        {
            try
            {
                //1.根据传递过来的参数信息，反射获取要执行的规则
                Type type = Assembly.GetExecutingAssembly().GetType(Rule.AssemblyName);
                if (type == null)
                {
                    return;
                }
                IBaseRule currentRule = Activator.CreateInstance(type) as IBaseRule;
                if (currentRule == null)
                {
                    return;
                }
                //2.执行

                //执行前纪录

                //执行中...
                currentRule.Execute(RuleParams);

                //执行后纪录
            }
            catch (Exception ex)
            {
                //throw;
            }
        }
    }
}
